home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / v7n22.arc / SHOWARGS.ARC / SHOWARGS.ASM < prev    next >
Assembly Source File  |  1988-12-07  |  4KB  |  112 lines

  1. ;----------------------------------------------------------------------
  2. ; SHOWARGS.ASM - demonstrate command line parsing with ARGC.ASM and ARGV.ASM
  3. ;
  4. ; Copyright (c) 1988 Ziff Communications Co.
  5. ; PC Magazine * Ray Duncan
  6. ;----------------------------------------------------------------------
  7.         .286
  8.  
  9. stdin   equ     0               ; standard input handle
  10. stdout  equ     1               ; standard output handle
  11. stderr  equ     2               ; standard error handle
  12.  
  13. cr      equ     0dh             ; ASCII carriage return
  14. lf      equ     0ah             ; ASCII line feed
  15. blank   equ     020h            ; ASCII blank
  16. tab     equ     09h             ; ASCII tab
  17.  
  18.         extrn   argc:near       ; returns argument count
  19.         extrn   argv:near       ; returns argument pointer
  20.                                 ; OS/2 API functions
  21.         extrn   DosWrite:far    ; write file or device
  22.         extrn   DosExit:far     ; terminate process
  23.  
  24. DGROUP  group   _DATA
  25.  
  26. _DATA   segment word public 'DATA'
  27.  
  28. curarg  dw      0               ; current command line argument
  29. totargs dw      0               ; total command line arguments
  30.  
  31. wlen    dw      ?               ; bytes actually written
  32.  
  33. msg1    db      cr,lf,"The command line contains "
  34. msg1a   db      "xx arguments"
  35. msg1_len equ $-msg1
  36.  
  37. msg2    db      cr,lf,"Argument "
  38. msg2a   db      "xx is:  "
  39. msg2_len equ $-msg2
  40.  
  41. _DATA   ends
  42. ;----------------------------------------------------------------------
  43. _TEXT   segment word public 'CODE'
  44.         assume  cs:_TEXT,ds:DGROUP
  45.  
  46. main    proc    far             ; entry point from OS/2
  47.  
  48.         call    argc            ; get and save number of
  49.         mov     totargs,ax      ; command line arguments
  50.  
  51.         mov     bx,offset msg1a ; convert argument count
  52.         call    b2dec           ; to ASCII for output
  53.                                 ; display argument count
  54.         push    stdout          ; standard output handle
  55.         push    ds              ; address of message
  56.         push    offset DGROUP:msg1
  57.         push    msg1_len        ; length of message
  58.         push    ds              ; receives bytes written
  59.         push    offset DGROUP:wlen
  60.         call    DosWrite        ; transfer to OS/2
  61.  
  62. main1:  mov     ax,curarg       ; display next argument
  63.         cmp     ax,totargs      ; are we all done?
  64.         je      main2           ; yes, exit
  65.  
  66.         mov     bx,offset msg2a ; no, convert argument
  67.         call    b2dec           ; number to ASCII
  68.                                 ; display argument number
  69.         push    stdout          ; standard output handle
  70.         push    ds              ; address of message
  71.         push    offset DGROUP:msg2
  72.         push    msg2_len        ; length of message
  73.         push    ds              ; receives bytes written
  74.         push    offset DGROUP:wlen
  75.         call    DosWrite        ; transfer to OS/2
  76.  
  77.         mov     ax,curarg       ; now get actual argument
  78.         call    argv            ; ES:BX=addr,AX=length
  79.  
  80.         push    stdout          ; standard output handle
  81.         push    es              ; command argument address
  82.         push    bx
  83.         push    ax              ; command argument length
  84.         push    ds              ; receives bytes written
  85.         push    offset DGROUP:wlen
  86.         call    DosWrite        ; transfer to OS/2
  87.  
  88.         inc     word ptr curarg ; go to next argument
  89.         jmp     main1
  90.  
  91. main2:  push    1               ; terminate process
  92.         push    0               ; return code = zero
  93.         call    DosExit         ; final exit to OS/2
  94.  
  95. main    endp
  96. ;----------------------------------------------------------------------
  97. ; convert binary 0-99 to decimal ASCII call with
  98. ; AL = binary data, BX = addr. for 2 chars.
  99. ;----------------------------------------------------------------------
  100. b2dec   proc    near
  101.  
  102.         aam             ; divide AL by 10, leaving AH=quotient, AL=remainder
  103.         add     ax,"00"         ; convert to ASCII
  104.         mov     [bx],ah         ; store ten's digit
  105.         mov     [bx+1],al       ; store one's digit
  106.         ret                     ; return to caller
  107.  
  108. b2dec   endp
  109.  
  110. _TEXT   ends
  111.         end     main            ; defines entry point
  112.